import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// // https://vite.dev/config/
// export default defineConfig({
//   plugins: [
//     vue(),
//     vueDevTools(),
//   ],
//   resolve: {
//     alias: {
//       '@': fileURLToPath(new URL('./src', import.meta.url))
//     },
//   },
// })


// https://vite.dev/config/
export default defineConfig(({ mode, command, }) => {

    // const root = process.cwd()
    // let env: any = {}
    // const isBuild = command === 'build'
    // if (!isBuild) {
    //     env = loadEnv(process.argv[3] === '--mode' ? process.argv[4] : process.argv[3], root)
    // } else {
    //     env = loadEnv(mode, root)
    // }
    // console.log('-->', env)
    return {
        base: '/static/wind',
        plugins: [
            vue(),
        ],
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src',
                    import.meta.url))
            }
        },
        server: {
            host: '0.0.0.0',
            port: 5173,
            proxy: {
                '/api': {
                    // target: 'http://192.168.10.163:8100',
                    target: 'https://ny.moutai.com.cn',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, 'api'),
                },
                '/dd': {
                    // target: 'http://192.168.10.163:8100',
                    target: 'https://ny.moutai.com.cn',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/dd/, ''),
                }
            }
        }
    }
})